// import Cookies from 'js-cookie'
// import qs from 'qs'
// _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
// Please ASK KEN to REVIEW code change if you need MODIFY this file
// _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
import moment from 'moment'
export default {
  data () {
    let year = new Date().getFullYear()
    return {
      mixinViewModuleOptions: {
        createdIsNeed: true,
        activatedIsNeed: false
      },

      loading: false,
      grid: null,

      dateRangeDefaultSetting: {
        format: 'yyyy-MM-dd',
        minDate: new Date('10/1/2019'),
        maxDate: new Date('1/1/2025'),
        weekStartDate: moment().subtract('days', 6).format(),
        weekEndDate: moment().subtract('days', 0).format(),
        monthStartDate: new Date(new Date(new Date().setDate(1)).toDateString()),
        monthEndDate: new Date(new Date(new Date(new Date().setMonth(new Date().getMonth() + 1)).setDate(0)).toDateString()),
        lastMonthStartDate: moment().subtract(1, 'months').date(1).format(),
        lastMonthEndDate: moment().date(0).format(),
        lastYearStartDate: new Date(year - 1, 1, 1).toDateString(),
        lastYearEndDate: new Date(year - 1, 11, 31).toDateString()
      },
      gridDefaultSetting: {
        dataSource: this.dataList,
        showColumnMenu: true,
        allowResizing: true,
        allowFiltering: true,
        filterSettings: { type: 'Excel' },
        allowGrouping: true,
        allowPaging: true,
        allowExcelExport: true,
        allowPdfExport: true,
        toolbar: ['PdfExport', 'CsvExport', 'ColumnChooser'], // 'ExcelExport',
        showColumnChooser: true,
        groupOptions: { columns: ['name'] },
        allowReordering: true,
        allowSorting: true,
        allowTextWrap: true,
        height: window.innerHeight - 230,
        pageSettings: { pageSize: 100, pageSizes: [10, 50, 100, 200, 1000], pageCount: 4 },
        groupSettings: {
          allowReordering: false,
          columns: [],
          disablePageWiseAggregates: false,
          enableLazyLoading: false,
          showDropArea: true,
          showGroupedColumn: false,
          showToggleButton: false
        }
      },
      pageOptions: {
        currentPage: 1,
        pageSize: 10,
        total: 0,
        layout: 'total, sizes, prev, pager, next, jumper'
      },
      dataList: []
    }
  },
  created () {
    if (this.mixinViewModuleOptions.createdIsNeed) {
      this.resetDataForm()
    }
  },
  activated () {
    if (this.mixinViewModuleOptions.activatedIsNeed) {
      this.query()
    }
  },
  methods: {
    query () {
      this.loading = true
      var _self = this
      this.getDataListAPI().then(({ data: res }) => {
        _self.dataList = res.data
        _self.pageOptions.total = res.data.total
        _self.grid.dataSourceSettings.dataSource = this.dataList
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    refreshGrid () {
      this.dataList = [...this.dataList]
    },
    resetDataForm () {
    },

    pageCurrentChangeHandle (e) {
      if (e) {
        this.pageOptions.currentPage = e
        this.query()
      }
    },
    pageSizeChangeHandle (e) {
      if (e) {
        this.pageOptions.currentPage = 1
        this.pageOptions.pageSize = e

        this.query()
      }
    },

    getDataListAPI () {

    },

    closeCurrentTab (data) {
      var tabName = this.$store.state.contentTabsActiveName
      this.$store.state.contentTabs = this.$store.state.contentTabs.filter(item => item.name !== tabName)
      if (this.$store.state.contentTabs.length <= 0) {
        this.$store.state.sidebarMenuActiveName = this.$store.state.contentTabsActiveName = 'home'
        return false
      }
      if (tabName === this.$store.state.contentTabsActiveName) {
        this.$router.push({ name: this.$store.state.contentTabs[this.$store.state.contentTabs.length - 1].name })
      }
    }
  }
}
